Omplus.base.define(Omplus.controllers.Controller, {
    omplusName:"gamesController"
});

Omplus.base.define(Omplus.models.Model, {
    omplusName:"GamesSearch",
    controller:"gamesController",
    value:{
        "name":{
            omplusType:"String"
        },
        netent:{
            omplusType:"String",
            value:"on"
        },
        delta:{
            omplusType:"Number",
            value:5
        },
        start:{
            omplusType:"Number",
            value:0
        }
    }
});

Omplus.models.GamesSearchModelProto = Omplus.base.extend(Omplus.models.Object, {
    omplusType:"GamesSearchModelProto",
    value:{
        "id_games":{
            omplusType:"Number"
        },
        "name":{
            omplusType:"String"
        },
        "banner_url":{
            omplusType:"String",
            nullable:"true"
        },
        "vendor":{
            omplusType:"String"
        }
    }
});

Omplus.base.define(Omplus.models.Model, {
    omplusName:"GamesSearchResults",
    controller:"gamesController",
    value:{
        games:{
            omplusType:"Array",
            omplusProto:"GamesSearchModelProto"
        },
        total:{
            omplusType:"Number"
        }
    }
});

Omplus.models.GamesProto = Omplus.base.extend(Omplus.models.Model, {
    omplusType:"GamesProto",
    value:{
        "id_games":{
            omplusType:"Number"
        },
        "name":{
            omplusType:"String"
        },
        "banner_url":{
            omplusType:"String",
            nullable:"true"
        },
        "small_banner_url":{
            omplusType:"String",
            nullable:"true"
        },
        temp_banner:{
            omplusType:"String",
            nullable:"true"
        },
        temp_small_banner:{
            omplusType:"String",
            nullable:"true"
        },
        "active":{
            omplusType:"Boolean"
        },
        "client":{
            omplusType:"String"
        },
        "date_added":{
            omplusType:"String"
        },
        "description":{
            omplusType:"String"
        },
        "favourite":{
            omplusType:"Boolean"
        },
        "free_spins":{
            omplusType:"Boolean"
        },
        "game_id":{
            omplusType:"String"
        },
        "src":{
            omplusType:"String"
        },
        "vendor":{
            omplusType:"String"
        },
        "vip":{
            omplusType:"Boolean"
        }
    }
});

Omplus.views.OpeningGameTabView = Omplus.base.extend(Omplus.views.OpeningTabView, {
    omplusType:"OpeningGameTabView",
    layout:{
        omplusType:"HorizontalLayout",
        width:"900px"
    },
    controller:"gamesController",
    components:[
        {
            omplusType:"Panel",
            omplusName:"GamesTabLeft",
            width:"300px",
            layout:{
                omplusType:"VerticalLayout"
            },
            components:[
                {
                    model:"gameChooser.current.id_games",
                    labelModel:"Assets.list.game_id_label.localValue",
                    inputType:"Label",
                    height:"40px"
                },
                {
                    omplusType:"TempUploader",
                    omplusName:"TempBanner",
                    controller:"gamesController",
                    model:"gameChooser.current.temp_banner",
                    callback:function () {
                        Omplus.globals.getObject("gameChooser").getAction("uploadGameBanner").run();
                    }
                },
                {
                    model:"gameChooser.current.banner_url",
                    labelModel:"Assets.list.banner_label.localValue",
                    inputType:"Image",
                    height:"180px"
                }
//                {
//                    omplusType:"TempUploader",
//                    omplusName:"TempSmallBanner",
//                    controller:"gamesController",
//                    model:"gameChooser.current.temp_small_banner_url",
//                    callback:function () {
//                        Omplus.globals.getObject("gameChooser").getAction("uploadGameSmallBanner").run();
//                    }
//                },
//                {
//                    model:"gameChooser.current.small_banner",
//                    labelModel:"Assets.list.small_banner_label.localValue",
//                    inputType:"Image",
//                    height:"100px"
//                }
            ]
        },
        {
            omplusType:"Panel",
            omplusName:"GamesTabMiddle",
            width:"300px",
            layout:{
                omplusType:"VerticalLayout"
            },
            components:[
                {
                    model:"gameChooser.current.name",
                    labelModel:"Assets.list.name_label.localValue"
                },
                {
                    model:"gameChooser.current.active",
                    labelModel:"Assets.list.active_label.localValue",
                    inputType:"CheckBox"
                },
                {
                    model:"gameChooser.current.client",
                    labelModel:"Assets.list.client_label.localValue"
                },
                {
                    model:"gameChooser.current.date_added",
                    labelModel:"Assets.list.date_added_label.localValue"
                },
                {
                    model:"gameChooser.current.description",
                    labelModel:"Assets.list.description_label.localValue"
                },
                {
                    model:"gameChooser.current.favourite",
                    labelModel:"Assets.list.favourite_label.localValue",
                    inputType:"CheckBox"
                },
                {
                    model:"gameChooser.current.free_spins",
                    labelModel:"Assets.list.free_spins_label.localValue",
                    inputType:"CheckBox"
                },
                {
                    model:"gameChooser.current.game_id",
                    labelModel:"Assets.list.game_id_label.localValue"
                },
                {
                    model:"gameChooser.current.src",
                    labelModel:"Assets.list.src_label.localValue"
                },
                {
                    model:"gameChooser.current.vendor",
                    labelModel:"Assets.list.vendor_label.localValue"
                },
                {
                    model:"gameChooser.current.vip",
                    labelModel:"Assets.list.vip_label.localValue",
                    inputType:"CheckBox"
                }
            ]
        },
        {
            omplusType:"Panel",
            omplusName:"GamesTabRight",
            width:"300px",
            layout:{
                omplusType:"VerticalLayout"
            },
            components:[
                {
                    omplusType:"Button",
                    omplusName:"saveGameButton",
                    model:"Assets.list.label_save_button.localValue",
                    controller:"languageController",
                    click:function() {
                        Omplus.globals.getObject("gameChooser").getAction("saveGame").run();
                    }
                }
            ]
        }
    ]
});

Omplus.base.define(Omplus.models.SingleChooser, {
    omplusName:"gameChooser",
    controller:"gamesController",
    omplusProto:"GamesProto",
    actions:[
        {
            omplusType:"Get",
            omplusName:"uploadGameBanner",
            proxy:{
                omplusType:"AjaxProxy"
            },
            requestModel:"gameChooser.current",
            responseModel:"gameChooser.current"
        },
        {
            omplusType:"Get",
            omplusName:"uploadGameSmallBanner",
            proxy:{
                omplusType:"AjaxProxy"
            },
            requestModel:"gameChooser.current",
            responseModel:"gameChooser.current"
        },
        {
            omplusType:"Get",
            omplusName:"saveGame",
            proxy:{
                omplusType:"AjaxProxy"
            },
            requestModel:"gameChooser.current",
            responseModel:"gameChooser.current"
        }
    ]
});

Omplus.base.define(Omplus.views.ManagementPanel, {
    omplusName:"gamesPanel",
    controller:"gamesController",
    renderTo:"managements",
    models:{
        chooser:"gameChooser",
        search:"GamesSearch",
        searchResult:"GamesSearchResults",
        searchResultList:"games",
        forDisplay:"name"
    },
    views:{
        chooser:{
            title:"Assets.list.games_label.localValue",
            components:[
                {
                    omplusName:"gameTabs",
                    omplusType:"OpeningTabPanel",
                    omplusProto:"OpeningGameTabView",
                    controller:"gamesController",
                    model:"gameChooser",
                    showModel:"name"
                }
            ]
        },
        search:[
            {
                model:"GamesSearch.name",
                labelModel:"Assets.list.name_label.localValue"
            },
            {
                inputType:"Select",
                model:"PerPages",
                showModel:"number",
                current:"forGames",
                controller:"languageController",
                labelModel:"Assets.list.label_per_page.localValue",
                perPage:true
            },
            {
                inputType:"Button",
                controller:"languageController",
                model:"Assets.list.label_search_button.localValue",
                cssClasses:["search-button"],
                labelWidth:"0%",
                inputWidth:"100%",
                searchButton:true
            }
        ],
        searchResult:[
            {
                labelModel:"Assets.list.game_id_label.localValue",
                width:"80px",
                omplusType:"Label",
                model:"id_games"
            },
            {
                labelModel:"Assets.list.name_label.localValue",
                width:"150px",
                omplusType:"Label",
                model:"name"
            },
            {
                labelModel:"Assets.list.banner_label.localValue",
                width:"200px",
                omplusType:"Image",
                model:"banner_url"
            },
            {
                labelModel:"Assets.list.vendor_label.localValue",
                width:"200px",
                omplusType:"Label",
                model:"vendor"
            },
            {
                omplusType:"Button",
                model:"Assets.list.details_label.localValue",
                width:"250px",
                controller:"languageController",
                getDetails:true
            }
        ]
    },
    tableProto:{
        omplusType:"Panel",
        components:[
            {
                omplusName:"tableColumnNameLabels",
                omplusType:"Panel",
                components:[],
                cssClasses:[
                    "table-header"
                ]
            },
            {
                omplusType:"DinamicTable",
                orientation:"vertical",
                rowsPerPage:5,
                rowHeight:"100px",
                rowCellWidths:[]
            }
        ]
    }
});